<template>
  <div>
    <el-dialog
      title="增加供应商"
      :visible.sync="visible"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      @close="closeDialog"
      
      width="500px"
    >
      <div class="warn">
        <p>
          <strong>说明:</strong>
          <br />标记*的必须录入数据的字段
        </p>
      </div>
      <div class="form"></div>
      <el-form ref="form" :model="submit" label-position="left" label-width="120px" size="mini">
        <el-form-item label="*分类">
          <el-select v-model="submit.classid" placeholder="请选择分类">
            <!-- <el-option label="区域一1213" value="shanghai"></el-option> -->
            <!-- <el-option label="区域二" value="beijing"></el-option> -->
            <el-option v-for="item in classList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="*编码">
          <el-input v-model="submit.code" ></el-input>
        </el-form-item>
        <el-form-item label="*供应商名称">
          <el-input v-model="submit.name"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="submit.address"></el-input>
        </el-form-item>
        <el-form-item label="联系人">
          <el-input v-model="submit.concact"></el-input>
        </el-form-item>
        <el-form-item label="手机">
          <el-input v-model="submit.phone"></el-input>
        </el-form-item>
        <el-form-item label="固话">
          <el-input v-model="submit.fixedline"></el-input>
        </el-form-item>
        <el-form-item label="QQ">
          <el-input v-model="submit.qq"></el-input>
        </el-form-item>
        <el-form-item label="备用联系人">
          <el-input v-model="submit.concact2"></el-input>
        </el-form-item>
        <el-form-item label="备用联系人手机">
          <el-input v-model="submit.phone2"></el-input>
        </el-form-item>
        <el-form-item label="备用联系人固话">
          <el-input v-model="submit.fixedline2"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="Submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    form: {
      style: Object
    }
  },
  data() {
    return {
      submit: {},
      visible: true,
      classList:[],
    };
  },
  methods: {
    Check() {
      if (
        this.submit.name == null ||
        this.submit.name == "" ||
        this.submit.code == null ||
        this.submit.code == "" ||
        this.submit.classid == null ||
        this.submit.classid == ""
      ) {
        this.$message.error("请录入必填数据的字段！");
        return false;
      }
      return true;
    },
    Submit() {
      // window.console.log(this.submit);

      if (this.Check()) {
        this.$http.post("supplier/insert", this.submit).then(response => {
          if (response.data == "success") {
            this.$message({
              message: "添加完成",
              type: "success"
            });
            this.NeedRefresh();
            this.visible = false;
          }
        });
      }
    },
    closeDialog() {
      this.$emit("dialog-close");
    },
    NeedRefresh() {
      this.$emit("refresh");
    },
    selectFather(node) {
      this.submit.orangeid = node.id;
      this.submit.orangename = node.name;
    },
    SureSelectOrange() {
      this.treeApp.visible = false;
    }
  },
  created() {
   this.$http.get("/supplierClass/list").then(response => {
        this.classList = response.data;
      });
    this.submit = JSON.parse(JSON.stringify(this.form));
  }
};
</script>

<style>
.form {
  margin-top: 20px;
}
</style>